let betRecord = function(){
    let html = '<div style="margin-top: 10px;margin-right: 20px">\n' +
        '    <form class="layui-form" action="javascript:;" id="selectStockForm">\n' +
        '        <div class="layui-form-item">\n' +
        '            <div class="layui-inline">\n' +
        '                <label class="layui-form-label">用户id</label>\n' +
        '                <div class="layui-input-inline">\n' +
        '                    <select name="userId" id="userId" lay-filter="gameKind" lay-search="">\n' +
        '                    </select>\n' +
        '                </div>\n' +
        '            </div>\n' +
        '            <div class="layui-inline">\n' +
        '                <label class="layui-form-label">派彩时间</label>\n' +
        '                <div class="layui-input-inline">\n' +
        '                    <select name="payoutTime" lay-search="">\n' +
        '                        <option value=""></option>\n' +
        '                        <option value="0">今天</option>\n' +
        '                        <option value="1">昨天</option>\n' +
        '                        <option value="2">一个月内</option>\n' +
        '                    </select>\n' +
        '                </div>\n' +
        '            </div>\n' +
        '        </div>\n' +
        '            <div class="layui-form-item">\n' +
            '            <div class="layui-inline">\n' +
            '                <label class="layui-form-label">游戏分类</label>\n' +
            '                <div class="layui-input-inline">\n' +
            '                    <select name="gameKind" id="gameKind" lay-filter="gameKind">\n' +
            '                    </select>\n' +
            '                </div>\n' +
            '            </div>\n' +
            '            <div class="layui-inline">\n' +
            '                <label class="layui-form-label">游戏平台</label>\n' +
            '                <div class="layui-input-inline">\n' +
            '                    <select name="gamePlatform" id="gamePlatform" lay-filter="gamePlatform">\n' +
            '                    </select>\n' +
            '                </div>\n' +
            '            </div>\n' +
        '                <div class="layui-inline">\n' +
        '                    <div class="layui-input-block">\n' +
        '                        <button class="layui-btn" lay-submit="" lay-filter="demo2">立即搜索</button>\n' +
        '                    </div>\n' +
        '                </div>\n' +
        '            </div>\n' +
        '\n' +
        '    </form>\n' +
        '</div>' +
        '<div style="margin-left: 10px;margin-right: 10px"><table class="layui-hide" id="test" lay-filter="test"></table></div>';
    layui.use(['table', 'form', 'jquery', 'element'], function () {
        var table = layui.table
            , form = layui.form
            , $ = layui.jquery
            , element = layui.element;

    $("#mainbody").html(html);
    //表格加载
    table.render({
        elem: '#test'
        , url: 'ftBetRecord/get'
        , toolbar: 'toolbarDemo'
        , title: '投注明细表'
        , id: 'layuiTable' //用作主键 做刷新用
        , page: true
        , limit: 10//默认每页显示数量
        , limits: [10, 20, 30]//每页显示数量类型
        , cols: [[
            {type: 'checkbox'}
            , {type: 'numbers',title: '序号',width: 50}
            , {field: 'betTime', title: '投注时间', width: 180, align: 'center'}
            , {field: 'userId', title: '用户id', width: 120, align: 'center'}
            , {field: 'betNo', title: '投注单号', width: 180, align: 'center'}
            , {field: 'gameName', title: '游戏名称', width: 150, align: 'center'}
            , {field: 'betAmount', title: '投注金额', width: 100, align: 'center',sort: true}
            , {field: 'pieAwarded', title: '已派奖', width: 100, align: 'center'}
        ]]
    });

        //加载下家列表
        $.ajax({
            type: "POST",
            url: "lowers/get",
            dataType: "json",
            async:false,
            contentType: "application/json",
            success: function (list) {
                var str = '<option value=""></option>';
                for (var i = 0; i < list.length; i++) {
                    str += '<option value="' + list[i].username + '">' + list[i].username + '</option>';
                }
                $("#userId").html(str);

            },
            error: function () {
                console.log("获取下家列表失败！");
            }
        });

        //加载游戏分类
        $.ajax({
            type: "POST",
            url: "ftGameKind/get",
            dataType: "json",
            async:false,
            contentType: "application/json",
            success: function (list) {
                var str = '<option value=""></option>';
                for (var i = 0; i < list.length; i++) {
                    str += '<option value="' + list[i].id + '">' + list[i].gameKind + '</option>';
                }
                $("#gameKind").html(str);

            },
            error: function () {
                console.log("获取游戏分类列表失败！");
            }
        });



    form.render();

        //下拉框选中事件
        form.on('select(gameKind)', function(data){
            let gameKind = data.value; //得到被选中的值
            let str = '<option value=""></option>';
            $.ajax({
                type: "POST",
                url: "ftGamePlatform/get",
                traditional: true,
                dataType: "json",
                async: false,
                data:{
                    "gameKind":gameKind
                },
                success: function (list) {

                    for (var i = 0; i < list.length; i++) {
                        str += '<option value="' + list[i].id + '">' + list[i].gamePlatform + '</option>';
                    }
                },
                error: function () {
                    console.log("请求游戏平台失败！");
                }
            });
            $("#gamePlatform").html(str);

            form.render();

        });

    //头工具栏事件
    table.on('toolbar(test)', function (obj) {
        var checkStatus = table.checkStatus(obj.config.id)
            , data = checkStatus.data; //获取选中的数据
        switch (obj.event) {
            case 'add':
                layer.open({
                    title: ['添加用户', 'font-size:18px;']
                    , shade: 0.6 //遮罩透明度
                    , area: ['630px','500px']//宽度
                    , type: 2
                    , anim: 1 //0-6的动画形式，-1不开启
                    , content: "/sys/user/addButton"
                    , success: function (layero, index) {
                        //layer高度自适应
                        // layer.iframeAuto(index);
                        table.reload('userTable');
                    }


                })
                break;
            case 'update':
                if (data.length === 0) {
                    layer.msg('请选择一行');
                } else if (data.length > 1) {
                    layer.msg('只能同时编辑一个');
                } else {
                    layer.open({
                        title: ['编辑用户', 'font-size:18px;']
                        , shade: 0.6 //遮罩透明度
                        , area: ['630px','500px']//宽度
                        , type: 2
                        , anim: 1 //0-6的动画形式，-1不开启
                        , content: "/sys/user/editButton/"+data[0].userId
                        , success: function (layero, index) {
                            //layer高度自适应
                            // layer.iframeAuto(index);
                            table.reload('userTable');
                        }
                        /*                           , end: function () {
                                                       var handle_status = $("#handle_status").val();
                                                       console.log(handle_status);
                                                       if (handle_status == 1) {

                                                           $("#handle_status").val("");
                                                           layer.msg('同上', {
                                                               icon: 1,
                                                               time: 1000 //2秒关闭（如果不配置，默认是3秒）
                                                           }, function () {
                                                               table.reload('userTable');
                                                           });
                                                       } else if (handle_status == 2) {
                                                           layer.msg('编辑失败',
                                                               {icon: 2, time: 1000}
                                                           )
                                                       }
                                                   }*/

                    })
                    break;
                }
                break;
            case 'delete':
                if (data.length === 0) {
                    layer.msg('请选择一行');
                } else {
                    //页面删除效果
                    //$(".layui-form-checked").closest('tr[data-index]').remove();
                    var arr = new Array();
                    for (var i = 0; i < data.length; i++) {
                        arr.push(data[i].userId);
                    }
                    layer.confirm("确定删除吗?",{

                            btn: ['确定', '取消']
                            ,title:"提示"
                        }, function (index, layero) {
                            console.log(arr);
                            $.ajax({
                                type: "POST",
                                url: "/sys/user/delete",
                                traditional: true,
                                dataType: "json",
                                contentType: "application/json",
                                data: JSON.stringify(arr),
                                success: function (data) {
                                    console.log(data);
                                    layer.msg("删除成功!",{ icon: 1, time: 1000 });
                                    table.reload('userTable');
                                },
                                error: function () {

                                    layer.msg(JSON.parse(data.responseText).message,{ icon: 1, time: 1000 });
                                }
                            });
                        }
                    );

                }
                break;
        }
        ;
    });


    //监听搜索按钮
    form.on('submit(demo2)', function (data) {
        let payoutTime = data.field.payoutTime;
        let gameKind = data.field.gameKind;
        let gamePlatform = data.field.gamePlatform;
        let userId = data.field.userId;
        let begin ;
        let end ;
        if(payoutTime == '0'){
            begin = new Date(new Date().toLocaleDateString()).getTime();
            end = begin+ 3600 * 1000 * 24;
        }else if(payoutTime == '1'){
            end = new Date(new Date().toLocaleDateString()).getTime();
            begin = end - 3600 * 1000 * 24;
        }else if(payoutTime == '2'){
            end = new Date(new Date().toLocaleDateString()).getTime();
            begin = end - 3600 * 1000 * 24 * 30;
        }
        table.reload('layuiTable', {
            where: {"gameKind": gameKind, "gamePlatform": gamePlatform, "userId": userId,"begin":begin,"end":end}
        });

    });
    var handleSwitch = function (content, data, isChecked) {
        var tableDiv = $(data.othis);
        var tableId = tableDiv.parent().find("input").eq(0).val();
        var tableBut = tableDiv.find("em").html();
        var tableButId;
        if (tableBut=="ON"){
            tableButId = 0;
        }
        if (tableBut=="OFF") {
            tableButId = 1;
        }
        layer.open({
            content: content
            , btn: ['确定', '取消']
            , yes: function (index, layero) {
                $.ajax({
                    url:'/sys/user/edit',
                    data:{
                        userId: tableId,
                        userStatus: tableButId
                    },
                    // dataType:'text',
                    type:'post',
                    success:function (data) {
                        console.log(data);
                        if (data == 'success'){
                            table.reload('userTable');
                        }else{
                            layer.msg('错误');
                        }
                    },
                    error: function (data) {

                        layer.msg(JSON.parse(data.responseText).message,{ icon: 1, time: 1000 });
                    }
                });
                data.elem.checked = isChecked;
                form.render();
                layer.close(layer.index);
                //按钮【按钮一】的回调
            }
            , btn2: function (index, layero) {
                //按钮【按钮二】的回调
                data.elem.checked = !isChecked;
                form.render();
                layer.close(layer.index);
                //return false 开启该代码可禁止点击该按钮关闭
            }
            , cancel: function () {
                //右上角关闭回调
                data.elem.checked = !isChecked;
                form.render();
                //return false 开启该代码可禁止点击该按钮关闭
            }
        });
        return false;
    }

    })
}
